package com.ln.Test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

    private final Map<String, List<bean>> mDataMap = new HashMap<>();

    //        String name="牛 7";
    String tip = "2";
    String name = "熊 5";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn_update).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (String next : mDataMap.keySet()) {
                    if (next.substring(0, 1).equals(tip)) {
                        List<bean> list = mDataMap.get(next);
                        for (int i = 0; i < Objects.requireNonNull(list).size(); i++) {
                            if (TextUtils.equals(name, list.get(i).name)) {
                                boolean show = list.get(i).show;
                                list.get(i).show = !show;
                                list.set(i, list.get(i));
                            }
                        }
                    }
                }
            }
        });
        findViewById(R.id.btn_query).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                for (String next : mDataMap.keySet()) {
                    if (next.substring(0, 1).equals(tip)) {
                        List<bean> list = mDataMap.get(next);
                        for (int i = 0; i < Objects.requireNonNull(list).size(); i++) {
                            if (TextUtils.equals(name, list.get(i).name)) {
                                if (TextUtils.equals(name, list.get(i).name)) {
                                    Toast.makeText(MainActivity.this, name + "is show" + list.get(i).show + "pos is" + i, Toast.LENGTH_SHORT).show();

                                }
                            }
                        }
                    }
                }
            }
        });
        initData();
        initData2();
    }

    private void initData2() {
        List<bean> list1 = new ArrayList<>();
        List<bean> list2 = new ArrayList<>();
        List<bean> list3 = new ArrayList<>();

        list1.add(new bean(0, true, "熊 0"));
        list1.add(new bean(1, false, "熊 1"));
        mDataMap.put("2-1", list1);

        list2.add(new bean(2, false, "熊 2"));
        list2.add(new bean(3, true, "熊 3"));
        list2.add(new bean(4, false, "熊 4"));
        list2.add(new bean(5, true, "熊 5"));
        list2.add(new bean(6, false, "熊 6"));
        mDataMap.put("2-4", list2);

        list3.add(new bean(7, true, "牛 7"));
        mDataMap.put("2-7", list3);
    }

    private void initData() {
        List<bean> list1 = new ArrayList<>();
        List<bean> list2 = new ArrayList<>();
        List<bean> list3 = new ArrayList<>();

        list1.add(new bean(0, true, "牛 0"));
        list1.add(new bean(1, false, "牛 1"));
        list1.add(new bean(2, true, "牛 2"));
        mDataMap.put("0-1", list1);

        list2.add(new bean(3, true, "牛 3"));
        list2.add(new bean(4, false, "牛 4"));
        list2.add(new bean(5, false, "牛 5"));
        list2.add(new bean(6, false, "牛 6"));
        mDataMap.put("0-4", list2);

        list3.add(new bean(7, true, "牛 7"));
        list3.add(new bean(8, true, "牛 8"));

        mDataMap.put("0-7", list3);
    }

    class bean {

        boolean show;
        int id;
        String name;

        public bean(int id, boolean show, String name) {
            this.show = show;
            this.id = id;
            this.name = name;
        }

        public boolean isShow() {
            return show;
        }

        public void setShow(boolean show) {
            this.show = show;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}